<template>
  <div class="gigbox">
    <video class="video_back" src="../../assets/video.mp4" muted autoplay loop />
    <div class="box">

      <div class="logo">
        <img src="../../assets/logo1.png" alt="">
      </div>
      <el-form ref="loginFormRef" style="width: 400px" :model="loginForm" :rules="loginFormRules">
        <el-form-item prop="account">
          <el-input v-model="loginForm.account" prefix-icon="el-icon-s-custom" />
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="loginForm.password" prefix-icon="el-icon-lock" />
        </el-form-item>
        <el-form-item prop="code">
          <el-input v-model="loginForm.code" prefix-icon="el-icon-warning">
            <template #suffix>
              <img :src="src" alt="" style="scale: 0.8" @click="getCaptcha">
            </template>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button class="btn" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
// import axios from 'axios'

export default {
  name: 'Login',
  data() {
    return {
      src: '',
      loginForm: {
        account: 'demo',
        password: 'hm#qd@23!',
        code: '',
        key: '1234'
      },
      loginFormRules: {
        account: [{ required: true, message: '账号不能为空', trigger: 'blur' }],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' }
        ],
        code: [
          { required: true, message: '验证码不能为空', trigger: 'blur' }
        ]
      },
      loading: false,
      passwordType: 'password',
      redirect: undefined
    }
  },
  created() {
    this.getCaptcha()
  },
  methods: {
    getCaptcha() {
      this.loginForm.key = Math.ceil(Math.random() * 1000)
      this.src =
        'https://slwl-api.itheima.net/manager/captcha?key=' +
        this.loginForm.key
    },
    async  login() {
      try {
        await this.$refs.loginFormRef.validate()
        // console.log('校验成功了')

        await this.$store.dispatch('user/login', this.loginForm)
        this.$router.push('/')
      } catch (e) {
        console.log(e)
      }
    }
  }
}
</script>

<style lang="scss">
.box {
  position: absolute;
  // bottom: 0;
  margin-top: 400px;
  left: 50%;
  transform:translate(-50%,-50%) ;
  border-radius: 10px;
  width: 500px;
  padding: 50px;
  background-color:white;
}
h3 {
  text-align: center;
  margin-bottom: 50px;
}
.btn {
  // margin-left: 150px;
  width: 100%;
  background-color: #e15536;
  color: white;
  font-weight: 700;
}
.el-input {
  height: 40px;
}
.logo {
  text-align: center;
  margin-bottom: 50px;
  img {
    width: 300px;
    scale: 0.5;
  }
}
.video_back {
 position: fixed;
 width: 100%;
 height: 100%;
 /* 默认，不保证保持原有的比例，内容拉伸填充整个内容容器。 */
 object-fit: fill;
 z-index: -9999;
}
.gigbox {
//  display: flex;
//  justify-content: center;
//  align-items: center;
position: relative;

}
</style>
